﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DaInterFace;
using DaInterFace.PDA;
using DaInterFace.PDA.P02;

namespace P02
{
    /// <summary>
    /// A11 获得质检指定ID取样信息
    /// </summary>
    public class A11 : IPDAChild
    {
        public void Code(IPDA handler, CodeResult CR, PDACodeUser user, String parameter)
        {
            P02A11P P = (P02A11P)handler.SerialApi.Deserialize(typeof(P02A11P), parameter, CR.SerialType);

            P02A11R R = new P02A11R();
            
            try
            {
                DataTable table = new DataTable();
                table.TableName = "SAMP";

                StringBuilder sql = new StringBuilder();
                sql.Append("Select A.FID,A.FBillNo BillNo,A.FInteger FCount,A.FTime BuildTime,A.FText1 OrderNo,B.FName SupplierName,C.FName ItemName From KEW_PurchSampling A \r\n");
                sql.Append("Left Join t_Supplier B On A.FBase=B.FItemID \r\n");
                sql.Append("Left Join KEW_PurchItem C On A.FBase1=C.FID \r\n");
                sql.Append("Left Join KEW_PurchOrderQty D On A.FID_SRC1=D.FID \r\n");
                sql.AppendFormat("Where A.FID={0}", Common.FilterSql(P.SampID));

                Recordset rs = handler.Data.ExeProcedure(P.BaseNo, sql.ToString());

                if (rs.Enable)
                {
                    table.Merge(rs.Data.Tables[0]);

                    R.Table = table;

                    CR.Content = handler.SerialApi.Serializer(typeof(P02A11R), R, CR.SerialType);
                    CR.Message = String.Format("操作员{0}获取账套：{1}，质检取样：{2}的信息", user.UserName, P.BaseNo, P.SampID);
                }
                else
                {
                    CR.Result = EnumResult.Error;
                    CR.Message = "数据库错误";
                }
            }
            catch (Exception ex)
            {
                CR.Result = EnumResult.Error;
                CR.Message = String.Format("发生错误:{0}", ex.Message);
            }
        }
    }


}
